<?php
/**
 * images de la page presse
 *
 * Description de la classe
 *
 * @author David
 */
class NewspapersImage extends Object {
    protected $id;
    protected $nom_image;
    protected $lien_petit;
    protected $lien_moyen;
    protected $lien_grand;

    function __construct($id="", $params=array()) {
        if($id != "") {
            $this->id = $id;
            foreach($params as $key => $p) {
                $this->$key = $p;
            }
        }
    }

    function __toString() {
        if(!isset($this->nom_image)) $this->load();
        return $this->nom_image;
    }

    public function load() {
        $db = Database::getInstance();
        $result = $db->query("SELECT * FROM presse_im WHERE id = '".$this->id."'");
        if(sizeof($result) > 0) {
            foreach($result[0] as $key => $p) {
                $this->$key = $p;
            }
            return;
        }
        if(DEBUG) echo("Objet inconnu");
        return false;
    }

    public static function getAllNewspapersImages(){
        $db = Database::getInstance();
        $sql = "SELECT * FROM presse_im ORDER BY id DESC";
        $result = $db->query($sql);
        $allNewspapersImages = array();
        foreach($result as $line){
            $allNewspapersImages[] = new NewspapersImage($line['id'], $line);
        }
        return $allNewspapersImages;
    }
}
?>
